<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JVM 内存管理与 OOM 分析指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .first-letter::first-letter {
            font-size: 3.5rem;
            font-weight: 700;
            float: left;
            line-height: 1;
            margin-right: 0.5rem;
            color: #667eea;
        }
        .section-divider {
            position: relative;
            text-align: center;
            margin: 4rem 0;
        }
        .section-divider::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 0;
            right: 0;
            height: 1px;
            background: linear-gradient(to right, transparent, #e5e7eb, transparent);
        }
        .section-divider span {
            background: white;
            padding: 0 2rem;
            position: relative;
            color: #9ca3af;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .icon-box {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        .step-number {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #f3f4f6;
            color: #667eea;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            font-size: 1.25rem;
            margin-right: 1rem;
            flex-shrink: 0;
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .fade-in-up {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">JVM 内存管理与 OOM 分析</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">深入理解 Java 虚拟机内存机制，掌握问题诊断与优化技巧</p>
            <div class="flex justify-center space-x-4">
                <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                    <i class="fas fa-memory mr-2"></i> 内存分析
                </span>
                <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                    <i class="fas fa-chart-line mr-2"></i> 性能优化
                </span>
                <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full">
                    <i class="fas fa-shield-alt mr-2"></i> 稳定保障
                </span>
            </div>
        </div>
    </section>

    <!-- Introduction -->
    <section class="max-w-4xl mx-auto px-6 py-16">
        <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12 card-hover">
            <p class="text-lg leading-relaxed text-gray-700 first-letter">
                在复杂的 Java 应用程序中，JVM 的内存使用情况直接影响到系统的性能和稳定性。通常，随着应用程序的运行，JVM 会分配和回收内存，但如果内存管理不当或出现意外情况，可能会导致内存不足（OutOfMemoryError，简称 OOM）。OOM 是一种严重的错误，会导致应用程序崩溃，因此在实际生产环境中，快速准确地分析和解决此类问题非常关键。
            </p>
        </div>
    </section>

    <!-- Memory Architecture Visualization -->
    <section class="max-w-6xl mx-auto px-6 py-8">
        <h2 class="text-3xl font-bold text-center mb-12 gradient-text">JVM 内存架构</h2>
        <div class="bg-white rounded-2xl shadow-xl p-8">
            <div class="mermaid">
                graph TB
                    JVM[JVM 内存结构]
                    JVM --> Heap[堆内存 Heap]
                    JVM --> NonHeap[非堆内存]
                    
                    Heap --> Young[年轻代 Young Gen]
                    Heap --> Old[老年代 Old Gen]
                    
                    Young --> Eden[Eden 区]
                    Young --> S0[Survivor 0]
                    Young --> S1[Survivor 1]
                    
                    NonHeap --> Metaspace[元空间 Metaspace]
                    NonHeap --> Stack[栈 Stack]
                    NonHeap --> Direct[直接内存 Direct Memory]
                    
                    style JVM fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style Heap fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
                    style NonHeap fill:#9f7aea,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>
    </section>

    <!-- Memory Analysis Steps -->
    <section class="max-w-6xl mx-auto px-6 py-16">
        <div class="section-divider">
            <span><i class="fas fa-microscope mr-2"></i>内存分析步骤</span>
        </div>
        
        <h2 class="text-4xl font-bold text-center mb-12 serif-font">内存使用情况的分析</h2>
        
        <div class="grid md:grid-cols-2 gap-8">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover fade-in-up">
                <div class="flex items-start">
                    <div class="step-number">1</div>
                    <div>
                        <h3 class="text-xl font-bold mb-3">获取 JVM 内存快照</h3>
                        <p class="text-gray-600 mb-4">通过 JVM 提供的工具（如 jmap）获取内存快照。内存快照包含当前 JVM 中的所有对象及其引用关系，有助于分析内存分配情况。</p>
                        <div class="bg-gray-100 rounded-lg p-4 font-mono text-sm">
                            <i class="fas fa-terminal mr-2 text-purple-600"></i>
                            jmap -dump:format=b,file=heap.hprof &lt;pid&gt;
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover fade-in-up" style="animation-delay: 0.1s">
                <div class="flex items-start">
                    <div class="step-number">2</div>
                    <div>
                        <h3 class="text-xl font-bold mb-3">使用分析工具</h3>
                        <p class="text-gray-600 mb-4">使用专业的内存分析工具（如 Eclipse MAT、VisualVM 等）加载 Heap Dump，分析哪些对象占用了大量内存。</p>
                        <div class="flex space-x-4">
                            <span class="inline-flex items-center px-3 py-1 bg-purple-100 text-purple-700 rounded-full text-sm">
                                <i class="fas fa-tools mr-1"></i> Eclipse MAT
                            </span>
                            <span class="inline-flex items-center px-3 py-1 bg-purple-100 text-purple-700 rounded-full text-sm">
                                <i class="fas fa-chart-bar mr-1"></i> VisualVM
                            </span>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover fade-in-up" style="animation-delay: 0.2s">
                <div class="flex items-start">
                    <div class="step-number">3</div>
                    <div>
                        <h3 class="text-xl font-bold mb-3">监控 GC 日志</h3>
                        <p class="text-gray-600 mb-4">通过 JVM 的 GC 日志，查看垃圾回收器的运行情况，包括回收了多少内存、用了多长时间、何时进行了 Full GC 等。</p>
                        <div class="bg-gray-100 rounded-lg p-4 font-mono text-sm">
                            <i class="fas fa-cog mr-2 text-purple-600"></i>
                            -XX:+PrintGCDetails -XX:+PrintGCDateStamps
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover fade-in-up" style="animation-delay: 0.3s">
                <div class="flex items-start">
                    <div class="step-number">4</div>
                    <div>
                        <h3 class="text-xl font-bold mb-3">分析内存区域</h3>
                        <p class="text-gray-600 mb-4">JVM 的内存主要分为堆、方法区、栈等区域。通过工具分析每个区域的内存使用情况，确定是哪个区域的内存使用异常。</p>
                        <div class="grid grid-cols-3 gap-2 text-center">
                            <div class="bg-purple-50 rounded p-2">
                                <i class="fas fa-database text-purple-600"></i>
                                <p class="text-sm mt-1">堆内存</p>
                            </div>
                            <div class="bg-purple-50 rounded p-2">
                                <i class="fas fa-layer-group text-purple-600"></i>
                                <p class="text-sm mt-1">方法区</p>
                            </div>
                            <div class="bg-purple-50 rounded p-2">
                                <i class="fas fa-bars text-purple-600"></i>
                                <p class="text-sm mt-1">栈内存</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- OOM Types -->
    <section class="bg-gray-100 py-16">
        <div class="max-w-6xl mx-auto px-6">
            <div class="section-divider">
                <span><i class="fas fa-exclamation-triangle mr-2"></i>OOM 类型分析</span>
            </div>
            
            <h2 class="text-4xl font-bold text-center mb-12 serif-font">OOM 后的分析</h2>
            
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-white rounded-xl shadow-md p-6 border-l-4 border-red-500">
                    <div class="icon-box bg-gradient-to-br from-red-500 to-pink-500 mb-4">
                        <i class="fas fa-memory"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">堆内存溢出</h3>
                    <p class="text-gray-600 mb-3">Heap Space OOM 通常意味着应用程序创建了太多对象，导致堆空间耗尽。</p>
                    <ul class="space-y-2 text-sm text-gray-600">
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>检查未释放的资源</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>排查死循环创建对象</li>
                        <li><i class="fas fa-check-circle text-green-500 mr-2"></i>优化大对象使用</li>
                    </ul>
                </div>
                
                <div class="bg-white rounded-xl shadow-md p-6 border-l-4 border-orange-500">
                    <div class="icon-